package com.lzm.back.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzm.back.entity.Event;
import com.lzm.back.entity.Notice;
import com.lzm.back.mapper.NoticeMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeService {
    @Resource
    private NoticeMapper noticeMapper;

    public void addNotice(Notice notice) {
        noticeMapper.insert(notice);
    }

    public void updateNotice(Notice notice) {
        noticeMapper.updateByPrimaryKeySelective(notice);
    }

    public void deleteNotice(Long id) {
        noticeMapper.deleteByPrimaryKey(id);
    }

    public Notice selectNoticeById(Long id) {
        return noticeMapper.selectByPrimaryKey(id);
    }

    public PageInfo<Notice> selectPage(Integer pageNum, Integer pageSize, String title) {
        PageHelper.startPage(pageNum, pageSize);
        List<Notice> noticeList = noticeMapper.selectPage(title);
        return PageInfo.of(noticeList);
    }
}
